﻿
using System.CodeDom;
using System.Text;
using System.Text.RegularExpressions;

namespace NUnitGenAddIn.Core
{
    /// <summary>
    /// Documentation Helper
    /// </summary>
    public static class DocumentationHelper
    {
        /// <summary>
        /// Gets the documentation header.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <returns><see cref="CodeCommentStatement"/> object for the Documentation Header</returns>
        public static CodeCommentStatement GetDocumentationHeader(string name)
        {
            name = name.Replace("Test", string.Empty);

            StringBuilder builder = new StringBuilder();
            builder.Append("<summary>\n");

            if (name.Equals("SetUp") || name.Equals("TearDown"))
            {
                builder.Append(" <see cref=\"NUnit\"/> ");
            }
            else
            {
                builder.Append("Tests the ");
            }

            Regex pascal = new Regex("[A-Z][a-z]*");

            foreach (Match m in pascal.Matches(name))
            {
                builder.Append(m.Value);
                builder.Append(" ");
            }

            builder.Append("\n </summary>");

            CodeCommentStatement comment = new CodeCommentStatement(builder.ToString(), true);
            return comment;
        }

        /// <summary>
        /// Gets the description header.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <returns>Document Description header for method</returns>
        public static string GetDocumentationHeaderString(string name)
        {
            name = name.Replace("Test", string.Empty);

            StringBuilder builder = new StringBuilder();
            builder.Append("<doc><summary>\n");
            builder.Append("Tests the ");

            Regex pascal = new Regex("[A-Z][a-z]*");

            foreach (Match m in pascal.Matches(name))
            {
                builder.Append(m.Value);
                builder.Append(" ");
            }

            builder.Append("\n</summary></doc>");

            return builder.ToString();
        }

    }
}
